<?php

namespace App\Core;

use App\Util\CommonHelper;
use EasySwoole\Http\Request;

class BaseListForm extends BaseForm{
    
    /** @var Request */
    public $request;
    
    private $_pagination = [];
    
    public function __construct(array $data, ?Request $request = null){
        parent::__construct($data);
        
        if($request){
            $this->request = $request;
            $this->_pagination = [
                'page'      => $this->request->getRequestParam('page') ?: 1,
                'page_size' => $this->request->getRequestParam('page_size') ?: 20,
            ];
        }
    }
    
    /**
     * @return array
     */
    public function getPagination() : array{
        return $this->_pagination;
    }
    
    /**
     * @param array $pagination
     * @return $this
     */
    public function setPagination(array $pagination) : self{
        $this->_pagination = $pagination;
        return $this;
    }
    
    public function checkField($field){
        return (strlen($field) > 0);
    }
    
}